package com.shengtsource.demo.controller;


import com.shengtsource.demo.service.IDemoService;
import com.shengtsource.mvc.anno.Autowired;
import com.shengtsource.mvc.anno.Controller;
import com.shengtsource.mvc.anno.RequestMapping;
import com.shengtsource.mvc.anno.Security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 权限说明：
 * admin 拥有所有权限
 * tom  拥有/demo/query、/demo/update 权限
 * jack 拥有/demo/update 权限
 * david 拥有 /demo/del 权限
 */
@Controller
@RequestMapping("/demo")
@Security({"admin"})
public class DemoController {


    @Autowired
    private IDemoService demoService;


    /**
     * URL: /demo/query?name=lisi
     * @param request
     * @param response
     * @param name
     * @return
     */
    @RequestMapping("/query")
    @Security({"tom"})
    public String query(HttpServletRequest request, HttpServletResponse response,String name) {
        return demoService.get(name);
    }

    /**
     * URL: /demo/query?name=lisi
     * @param request
     * @param response
     * @param name
     * @return
     */
    @RequestMapping("/update")
    @Security({"jack","tom"})
    public String update(HttpServletRequest request, HttpServletResponse response,String name) {
        return demoService.get(name);
    }

    /**
     * URL: /demo/query?name=lisi
     * @param request
     * @param response
     * @param name
     * @return
     */
    @RequestMapping("/del")
    @Security({"david"})
    public String del(HttpServletRequest request, HttpServletResponse response,String name) {
        return demoService.get(name);
    }
}
